# This file is part of ti-sph.

project(
    'ti-sph',
    'fortran', 'c',
    version : '0.3.5',
    license : 'All rights reserved',
    meson_version : '>= 0.50.0',
    default_options : [
        'buildtype=debugoptimized',
    ],
)

# 设置编译器选项，目前仅支持 Intel 和 GCC Fortran 编译器
dialect = ''
if meson.get_compiler('fortran').get_id() == 'intel'
    if host_machine.system() == 'windows'
        dialect = ['/4Yd']
    else
        dialect = ['-implicitnone']
    endif
endif

if meson.get_compiler('fortran').get_id() == 'gcc'
    dialect = ['-fimplicit-none']
endif

add_global_arguments(
    dialect,
    language : 'fortran',
)

seakeeping_dep = subproject('seakeeping').get_variable('seakeeping_dep')
argparse_f_dep = subproject('argparse-f').get_variable('argparse_f_dep')
h5part_dep = subproject('h5part').get_variable('h5part_dep')

sph_src = files()
subdir('src')

sph_lib = library(
    'engine',
    sph_src,
    install : true,
    dependencies : [
        dependency('openmp'),
        seakeeping_dep,
        argparse_f_dep,
        h5part_dep,
    ],
)

executable(
    'engine',
    'src/app/main.F90',
    link_with : [
        sph_lib,
    ],
    dependencies : [
        seakeeping_dep,
        argparse_f_dep,
    ],
    install : true,
)

testdrive_dep = subproject('test-drive').get_variable('testdrive_dep')
test_src = files(
    'test/test_density_summation.f90',
    'test/test_EoS.f90',
    'test/test_external_force.f90',
    'test/test_internal_force.f90',
    'test/test_load_toml.F90',
    'test/test_math.f90',
    'test/test_smoothed_kernel_function.f90',
)

test_lib = library(
    'test-lib',
    sources: test_src,
    link_with : [
        sph_lib,
    ],
    dependencies : [
        seakeeping_dep,
        testdrive_dep,
    ],
)

test(
    'engine',
    executable(
        'check',
        'test/check.F90',
        link_with : [
            test_lib,
        ],
        dependencies : [
            testdrive_dep,
        ],
    ),
)
